#include <iostream>
using namespace std;

/*
    【题目199】编写一个程序，设计一个Cdate类，满足以下条件。
        (1)输出日期格式为：日-月年：
        (2)输出在当前日期上加两天后的日期：
        (3)设置日期。
*/

bool isLeapYear(int year)
{
    if (year % 4 == 0)
    {
        if (year % 100 != 0)
        {
            return true;
        }
        else
        {
            if (year % 400 == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    return false;
}

bool isDateValid(int day, int month, int year)
{
    if (year < 0)
    {
        cout << "输入的年份有误" << endl;
        return false;
    }
    if (month < 1 || month > 12)
    {
        cout << "输入的月份有误" << endl;
        return false;
    }
    if (day < 1 || day > 31)
    {
        cout << "输入的日期有误" << endl;
        return false;
    }
    if (month == 2 && day > 28 && !isLeapYear(year))
    {
        cout << "输入的日期有误" << endl;
        return false;
    }
    else if (month == 2 && day > 29 && isLeapYear(year))
    {
        cout << "输入的日期有误" << endl;
        return false;
    }
    else if (month == 4 || month == 6 || month == 9 || month == 11)
    {
        if (day > 30)
        {
            cout << "输入的日期有误" << endl;
            return false;
        }
    }
    return true;
}

bool isThreeOneDay(int month)
{
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
    {
        return true;
    }
    return false;
}

class Cdate
{
public:
    Cdate(int day, int month, int year)
    {
        this->day = day;
        this->month = month;
        this->year = year;
    }
    void show()
    {
        cout << day << "-" << month << "-" << year << endl;
    }
    void addTwoDays()
    {
        day += 2;
        if (month == 2 && day > 28 && !isLeapYear(year))
        {
            day -= 28;
            month++;
        }
        else if (month == 2 && day > 29 && isLeapYear(year))
        {
            day -= 29;
            month++;
        }
        else if (isThreeOneDay(month) && day > 31)
        {
            day -= 31;
            month++;
        }
        else if (!isThreeOneDay(month) && day > 30)
        {
            day -= 30;
            month++;
        }
        if (month > 12)
        {
            month -= 12;
            year++;
        }
        if (isDateValid(day, month, year))
        {
            cout << "加两天后的日期是：";
            show();
        }
    }
    void setAttribute(int day, int month, int year)
    {
        if (isDateValid(day, month, year))
        {
            this->day = day;
            this->month = month;
            this->year = year;
        }
    }

private:
    int day;
    int month;
    int year;
};

int main()
{
    Cdate cdate(27, 2, 2020);
    cdate.show();
    cdate.addTwoDays();
    cdate.setAttribute(14, 10, 2025);
    cdate.show();

    return 0;
}